<template>
  <div o-Container>
    <o-list v-bind:source="list.task" v-bind="{created:create,modified:modify,exported:output}"/>

    <o-dialog v-bind:source="panel" v-bind="{opened:loadPanel,closed:loadPanel}">
      <template slot="content">
        <o-item v-bind:source="item.task" v-bind="{loaded:load,saved:save,backed:back}"></o-item>
        <o-list v-bind:source="list.task_log"/>
      </template>
    </o-dialog>
  </div>
</template>

<script>
  export default {
    name: "mms_engine_mqtt_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
    data() {
      return {
        octopus: this.$parent.octopus,
        //列表 数据
        list: {
          task: {
            data: {
              id: 342,
              cellData: [
                {name: "Name", searchKey: "LIKE", width: 300},// 只加载MQTT服务器
                {name: "TypeID", searchKey: "="},
                {name: "IntervalID", searchKey: "="},
                {name: "OffsetTypeID", searchKey: "=", width: 90},
                {name: "OffsetMinute", width: 100},
                {name: "NextRunDate", width: 150},
                {name: "Enable", width: 60, searchKey: "="},
                {name: "CreateUserID", width: 100},
                {name: "CreateDate", width: 150},
              ],
            },
          },
          task_log: {
            data: {
              id: 542,
              cellData: [
                {name: "TaskID", show: false, filterKey: "="},
                {name: "Status", width: 50},
                {name: "PlanRunDate", width: 150},
                {name: "RealRunDate", width: 150},
                {name: "CompleteDate", width: 150},
                {name: "Content", width: 2700},
              ],
              height: "200px",
            },
          },
        },
        // 创建页面和修改页面的需要的数据
        item: {
          task: {
            data: {
              id: 342,
              value: "",
              cellData: [
                {name: "Name"},// 只加载MQTT服务器
                {name: "TypeID"},
                {name: "Enable"},
                {name: "IntervalID"},
                {name: "OffsetTypeID"},
                {name: "OffsetMinute"},
                {name: "NextRunDate"},
                {name: "CreateUserID"},
                {name: "CreateDate"},
                {name: "Command"},
                {name: "Note"}
              ],
            }
          },
        },
        taskID: -1,
        panel: {
          visible: false
        },
      }
    },
    created: function () {
      this.init();
    },
    methods: {
      // 适配 平台 和 用户
      init: function () {

      },
      load: function (data) {
        // alert(JSON.stringify(data));
        // 得到TableID对象
        let ListFilterData = $.grep(this.list.task_log.data.cellData, function (value) {
          return value.name == "TaskID";//筛选出消息源ID编号
        })[0];
        // 如果Menu有主键值，说明是更新动作，否则创建动作，没有的加了也白加。
        if (this.item.task.data.value) {
          // 定义TableID具体内容
          ListFilterData.filterValue = this.item.task.data.value;
        } else {
          // 新创建页面时默认-1，查不到，最牛逼。
          ListFilterData.filterValue = -1;
        }
        this.list.task_log.control.load();

        // 更新最新更新人
        // this.octopus.tools.parseCell(this.item.datasource.data, "UpdateDate").defaultValue =  this.octopus.tools.date("yyyy-MM-dd HH:mm:ss");
        // this.octopus.tools.parseCell(this.item.datasource.data, "UpdaterID").defaultValue =  this.octopus.passport.id.toString();
      },
      loadPanel: function (data) {
        //
      },
      create: function () {
        this.item.task.data.value = null;
        this.item.task.control.load();
        this.panel.visible = true;
      },
      modify: function (row) {
        this.taskID = row.ID;
        this.item.task.data.value = row.ID;
        this.item.task.control.load();


        this.panel.visible = true;
      },
      save: function (data) {
        this.octopus.tips.success(data);
        // 刷新list
        this.list.task.control.load();
        this.back();
      },
      back: function () {
        this.panel.visible = false;
      },
      output: function (data) {
        this.octopus.tips.success("下载完成。");
      },
    },
    props: ["oData"]
  }
</script>
